<template>
  <div class="list-container">
    <el-form class="search-panel" v-model="formData" :inline="true">
      <el-form-item
        label-width="100px"
        class="search-time"
        label="考勤时间："
        prop="time"
      >
        <el-date-picker
          style="width: 250px"
          v-model="formData.startToEnd"
          type="daterange"
          range-separator="~"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="yyyy-MM-dd"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label-width="120px" label="日工资表状态：">
        <el-select v-model="formData.status" placeholder="请选择">
          <el-option
            v-for="item in statusOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
      
      <el-form-item style="width:100px;text-align:right;">
        <el-button type="primary" @click="onSubmit">查询</el-button>
      </el-form-item>
    </el-form>
    <div class="table-panel">
      <!-- <el-row class="table-operate">
        <el-button
          type="primary"
          icon="el-icon-upload2"
          @click="generateMAttendance"
        >
          生成月考勤
        </el-button>
      </el-row> -->
      <el-table
        :data="tableData"
        style="width: 100%"
      >
        <el-table-column type="index" align="center" width="55" label="序号">
        </el-table-column>
        <el-table-column prop="date" min-width="100" label="考勤时间" align="center">
        </el-table-column>
        <el-table-column prop="personNumber" min-width="80" label="考勤人数" align="center">
        </el-table-column>
        <el-table-column prop="totalWage" min-width="150" label="参照日工资合计" align="center">
          <template slot-scope="scope">
            <div>¥ {{scope.row.totalWage}}</div>
          </template>
        </el-table-column>
        <el-table-column prop="actualWage" min-width="150" label="实际日工资合计" align="center">
          <template slot-scope="scope">
            <div>¥ {{scope.row.actualWage}}</div>
          </template>
        </el-table-column>
        <el-table-column prop="confirmationRate" min-width="100" label="工资确认率" align="center">
        </el-table-column>
        <el-table-column width="180" label="操作" align="center" fixed="right">
          <template slot-scope="scope">
            <el-button
              @click.native.prevent="checkRow(scope)"
              type="text"
              icon="el-icon-search"
              >查看</el-button
            >
            <!-- <el-button
              @click.native.prevent="deleteRow(scope)"
              type="text"
              icon="el-icon-delete"
              >删除</el-button
            > -->
          </template>
        </el-table-column>
      </el-table>
      <el-row class="page">
        <div class="page-tag">
          共{{ Math.ceil(totalData / pageSize) }}页/{{ totalData }}条数据
        </div>
        <el-pagination
          background
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page.sync="currentPage"
          :page-sizes="[10, 20, 50]"
          :page-size="pageSize"
          layout="sizes, prev, pager, next, jumper"
          :total="totalData"
        >
          >
        </el-pagination>
      </el-row>
    </div>
  </div>
</template>

<script>
import {dailyAttendanceStatisticList,getAge} from "@/api/attendance.js"
import {dailyWageStatistic} from "@/api/wage.js"
export default {
  data() {
    return {
      formData: {
        startToEnd: null,
        status: -1,
        mode: -1,
      },
      statusOptions: [
        { value: -1, label: "全部" },
        { value: 0, label: "未确认" },
        { value: 1, label: "已确认" },
      ],
      currentPage: 1,
      pageSize: 10,
      totalData: 0,
      tableData: [],
    };
  },
  created(){
    this.getDate()
    this.getDailyWageStatistic()
  },
  methods: {
    getDate(){
      var dd = new Date();
      var y= dd.getFullYear()
      var m= dd.getMonth()+1
      var d=dd.getDate()
      const end=y+'-'+m+'-'+d
      const start=y+'-'+m+'-01'
      this.formData.startToEnd=[start,end]
    },
    // 获取日考勤统计列表
    getDailyWageStatistic(){
      // console.log(this.formData)
      dailyWageStatistic({
        currentPage:this.currentPage,
        pageSize:this.pageSize,
        startTime:this.formData.startToEnd==null?null:this.formData.startToEnd[0],
        endTime:this.formData.startToEnd==null?null:this.formData.startToEnd[1],
        confirmStatus:this.formData.status
      }).then(res=>{
        console.log(res)
        this.tableData = res.data.data.records
        this.totalData = res.data.data.total
      })
    },
    onSubmit() {
      // console.log(this.formData)
      this.getDailyWageStatistic()
    },
    handleSelectionChange(){},
    handleSizeChange(val) {
      this.pageSize = val
      this.getDailyWageStatistic()
    },
    handleCurrentChange(val) {
      this.currentPage = val
      this.getDailyWageStatistic()
    },
    checkRow(res){
        // console.log(res)
        this.$router.push({path:'/wage/daily/list',query:{date:res.row.date}})
    },
    deleteRow(res){},
    jump(){
      this.$router.push({path:'/wage/daily/list'})
    }
  },
};
</script>